﻿using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SocketTool.ViewModels.ControlViewModel;
using SocketTool.ViewModels.Protocols;
using SocketTool.ViewModels.TCP;

namespace SocketTool.ViewModels
{
    public class ViewModelLocator
    {
        private IServiceProvider mServiceProvider;
        public void Initialize(IServiceProvider serviceProvider)
        {
            this.mServiceProvider = serviceProvider;
        }

        public ReqMessageParamViewModel ReqMessageParamVM
        {
            get
            {
                using (var scope = this.mServiceProvider.CreateScope())
                    return scope.ServiceProvider.GetRequiredService<ReqMessageParamViewModel>();
            }
        }
        
        public MainWindowViewModel MainVM
        {
            get
            {
                using (var scope = mServiceProvider.CreateScope())
                    return scope.ServiceProvider.GetRequiredService<MainWindowViewModel>();
            }
        }

        public GlobalViewModel GlobalVM
        {
            get
            {
                using (var scope = mServiceProvider.CreateScope())
                {
                    return scope.ServiceProvider.GetRequiredService<GlobalViewModel>();
                }
            }
        }

        public TCPClientViewModel TCPClientVM
        {
            get
            {
                using (var scop = mServiceProvider.CreateScope())
                    return scop.ServiceProvider.GetRequiredService<TCPClientViewModel>();
            }
        }


        public ProtocolManageViewModel ProtocolManageVM
        {
            get
            {
                using (var scrop = this.mServiceProvider.CreateScope())
                {
                    return scrop.ServiceProvider.GetRequiredService<ProtocolManageViewModel>();
                }
            }
        }
    }
}
